#include "py32f0xx.h"
#include "py32f0xx_ll_utils.h"

static void InitSysTick(uint32_t HCLKFrequency, uint32_t Ticks)
{
  /* Configure the SysTick to have interrupt in 1ms time base */
  SysTick->LOAD  = (uint32_t)((HCLKFrequency / Ticks) - 1UL);  /* set reload register */
  SysTick->VAL   = 0UL;                                       /* Load the SysTick Counter Value */
  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
                   SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk;                   /* Enable the Systick Timer */
}

void Delay_Init(void)
{
  InitSysTick(24000000, 1000);
}


volatile uint32_t tick = 0;
volatile uint32_t gSystick = 0;

void Delay_Ms(uint32_t ms)
{
  tick = 0;

  while(tick < ms);
}

uint32_t SysTick_Get(void)
{
  return gSystick;
}

